package com.bestdreamer.thread_stream;

import sun.tools.asm.CatchData;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class Demo1StreamRun {

    public static void main(String[] args) {

        try{
            Demo1WriteData writeData = new Demo1WriteData();
            Demo1ReadData readData = new Demo1ReadData();

            PipedInputStream inputStream = new PipedInputStream();
            PipedOutputStream outputStream = new PipedOutputStream();

            //inputStream.connect(outputStream);
            outputStream.connect(inputStream);

            Demo1ThreadRead threadRead = new Demo1ThreadRead(readData, inputStream);
            threadRead.start();

            Thread.sleep(2000);

            Demo1ThreadWrite threadWrite = new Demo1ThreadWrite(writeData, outputStream);
            threadWrite.start();
        }catch (IOException e){
            e.printStackTrace();
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
